package br.com.monise.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.monise.model.Aprendiz;
import br.com.monise.model.Recurso;
import br.com.monise.util.GenericDao;

public class RecursoDAO extends GenericDao<Recurso> {
	
	public List<Recurso> getRecursoSemAvalicao(Aprendiz aprendiz){
		EntityManager manager = getEntityManager();
		
		manager.getTransaction().begin();
        Query query = manager.createQuery("select r from Recurso r where r.idRecurso not in (select a.recurso.idRecurso from Avaliacao a where a.aprendiz.idAprendiz = :aprendiz)");
		query.setParameter("aprendiz", aprendiz.getIdAprendiz());

		@SuppressWarnings("unchecked")
	    List<Recurso> recursos = query.getResultList();

		manager.getTransaction().commit();;

		return recursos;
	}
	
	public List<Recurso> getRecursosAvalidoAprendiz(Aprendiz aprendiz){
		EntityManager manager = getEntityManager();
		
		manager.getTransaction().begin();
        Query query = manager.createQuery("select r from Recurso r where r.idRecurso in (select a.recurso.idRecurso from Avaliacao a where a.aprendiz.idAprendiz = :aprendiz)");
		query.setParameter("aprendiz", aprendiz.getIdAprendiz());

		@SuppressWarnings("unchecked")
	    List<Recurso> recursos = query.getResultList();

		manager.getTransaction().commit();;

		return recursos;
	}

}
